package ar.com.personalTravellers.daos.impl;

import java.util.Collection;

import org.hibernate.criterion.Restrictions;

import ar.com.personalTravellers.beans.Hotel;
import ar.com.personalTravellers.beans.HotelType;
import ar.com.personalTravellers.beans.Neighborhood;
import ar.com.personalTravellers.daos.HotelDAO;
import ar.com.personalTravellers.daos.factory.PTDAOFactory;

import com.angel.architecture.persistence.ids.ObjectId;
import com.angel.dao.generic.impl.GenericSpringHibernateDAO;

/**
 *
 * @author William
 */
public class HotelSpringHibernateDAO extends GenericSpringHibernateDAO<Hotel, ObjectId> implements HotelDAO {

    public HotelSpringHibernateDAO() {
        super(Hotel.class, ObjectId.class);
    }

    public Hotel findUniqueByName(String name) {
        return super.findUnique("name", name);
    }

    public Collection<Hotel> findAllByQuantityRooms(Integer quantityRooms) {
        return super.findAllByCriteria(Restrictions.sizeEq("rooms",quantityRooms));
    }

    public Collection<Hotel> findAll(){
        Collection<Hotel> entities = super.findAllByCriteria();
        for(Hotel hotel: entities){
            hotel.getRooms();
        }
        return entities;
    }

    public Collection<Hotel> findAllByNeighborhoodName(String neighborhoodName) {
        Neighborhood neighborhood = PTDAOFactory.createInstance().getNeighborhoodDAO().findUniqueByName(neighborhoodName);
        return super.findAll("address.neighborhood", neighborhood);  
    }

    public Collection<Hotel> findAllByHotelType(String hotelTypeDescription) {
        HotelType hotelType = HotelType.valueOf(hotelTypeDescription);
        Collection<Hotel> hotels = super.findAll("type", hotelType);
        return hotels; 
    }
}